home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / findMenuItem.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  11.6 KB  |  441 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date: Oct 1999
  22. //
  23. //<doc>
  24. //<name findMenuItem>
  25. //<owner "Alias|Wavefront Unsupported">
  26. //
  27. //<synopsis>
  28. //        findMenuItem;
  29. //
  30. //<description>
  31. //        Displays a window that takes a text string and searches
  32. //        the main Maya window menus for that string. 
  33. //<P>
  34. //        The search can be slow if Maya has just started as the
  35. //        menus need to be built before they can be searched.
  36. //
  37. //<returns>
  38. //        None.
  39. //
  40. //</doc>
  41.  
  42.  
  43. global proc int searchOneMenu(
  44.     string $thisMenu, string $searchString, string $path)
  45. {
  46.     global string $gMainWindow;
  47.     setParent $gMainWindow;
  48.  
  49.     int $numItems = `menu -q -ni $thisMenu`;
  50.     if ($numItems == 0) { 
  51.         // Try to build the menu
  52.         string $pmCmd = `menu -q -pmc $thisMenu`;
  53.         catch(eval($pmCmd));
  54.         $numItems = `menu -q -ni $thisMenu`;
  55.     }
  56.  
  57.     if ($numItems == 0) return 0;
  58.  
  59.     int $gotOne = 0;
  60.     
  61.     string $items[] = `menu -q -ia $thisMenu`;
  62.     setParent -m $thisMenu;
  63.     for ($i=0; $i < $numItems; ++$i) {
  64.  
  65.         // Handle option boxes
  66.         if (`menuItem -q -iob $items[$i]`) continue;
  67.         // Handle the dividers
  68.         if (`menuItem -q -d $items[$i]`) continue;
  69.  
  70.         string $label = `menuItem -q -l $items[$i]`;
  71.         string $menuLabel;
  72.  
  73.         if (!`checkBox -q -v searchCaseSensitive`) {
  74.             $menuLabel = tolower ($label);
  75.         } else {
  76.             $menuLabel = $label;
  77.         }
  78.         // Remove the ... on menu items
  79.         $menuLabel = substituteAllString($menuLabel, ".", "");
  80.  
  81.         if (`gmatch $menuLabel $searchString`) {
  82.             scrollField -edit -it ($path+$label+"\n") 
  83.                 searchResultsTextField;
  84.             $gotOne = 1;
  85.         } 
  86.         
  87.         if (`menuItem -q -sm $items[$i]`) {
  88.             // Check for submenus
  89.             string $newPath = $path+$label+"->";
  90.             if (searchOneMenu($items[$i], $searchString, $newPath)) {
  91.                 $gotOne = 1;
  92.             }
  93.         }
  94.         setParent -m ..;
  95.     }
  96.     return $gotOne;
  97. }
  98.  
  99. global proc int oldMenuSearch (string $searchString)
  100. {
  101.     int $retVal = false;
  102.     string $version = `about -v`;
  103.  
  104.     // Note: The missing break statements in the outer loop    are intentional
  105.     // If the item isn't found for the current version, look at old versions.
  106.     // Additions to this should always put new versions at the top.
  107.  
  108.     switch ($version) {     
  109.  
  110.     // Maya 4 cases
  111.     //
  112.     case "4.0Beta1":
  113.     case "4.0":
  114.         $retVal = true;
  115.         switch ($searchString) {
  116.             //
  117.             // Removed items
  118.             //
  119.             case "*layer bar*":
  120.             case "*display layer editor*":
  121.                 scrollField -edit 
  122.                     -text ("This menu item has been removed.\n"
  123.                     + "Use the Layer Editor below the Channel Box instead.")
  124.                     searchResultsTextField;
  125.                 break;
  126.  
  127.             case "*uninstall current settings*":
  128.                 scrollField -edit 
  129.                     -text ("This menu item has been renamed to\n"
  130.                     + "Polygons->Tool Options->Reset to Default Settings")
  131.                     searchResultsTextField;
  132.                 break;
  133.  
  134.             default:
  135.                 $retVal = false;
  136.                 break;
  137.         }
  138.         if ($retVal) break;
  139.  
  140.     // Maya 3 cases
  141.     //
  142.     case "3.0Beta2":
  143.     case "3.0":
  144.     case "3.0.1":
  145.         $retVal = true;
  146.         switch ($searchString) {
  147.             //
  148.             // Removed items
  149.             //
  150.             case "*create display layer*":
  151.                 scrollField -edit 
  152.                     -text ("This menu item has been removed.\n"
  153.                     + "Use the Layer Bar or Display Layer Editor instead.")
  154.                     searchResultsTextField;
  155.                 break;
  156.  
  157.             // No helpful suggestions for these
  158.             case "*shading groups*":
  159.             case "*show edits one level finer*":
  160.             case "*run-up and cache*":
  161.             case "*cache current frame*":
  162.                 scrollField -edit 
  163.                     -text "This menu item has been removed."
  164.                     searchResultsTextField;
  165.                 break;
  166.  
  167.             case "*reverse and propagate*":
  168.                 scrollField -edit 
  169.                     -text ("This menu item has been removed.\n"
  170.                     + "It is now an option in the Reverse Option Box.")
  171.                     searchResultsTextField;
  172.                 break;
  173.  
  174.             case "*nurbs geometry*":
  175.                 scrollField -edit 
  176.                     -text ("This menu item has been removed.\n\n"
  177.                     + "Use one of the below instead:\n"
  178.                     + "Edit->Select All by Type->NURBS Curves\n"
  179.                     + "Edit->Select All by Type->NURBS Surfaces")
  180.                     searchResultsTextField;
  181.                 break;
  182.  
  183.             case "*add air*":
  184.             case "*add drag*":
  185.             case "*add gravity*":
  186.             case "*add newton*":
  187.             case "*add radial*":
  188.             case "*add turbulence*":
  189.             case "*add uniform*":
  190.             case "*add vortex*":
  191.                 scrollField -edit 
  192.                     -text ("This menu item has been removed.\n"
  193.                     + "Create the field, then use \n"
  194.                     + "Fields->Attach to Selected Object as Source")
  195.                     searchResultsTextField;
  196.                 break;
  197.  
  198.             //
  199.             // Renamed items
  200.             //
  201.             case "*add emitter*":
  202.                 scrollField -edit 
  203.                     -text ("This menu item has been renamed.\n"
  204.                     + "Particles->Emit from Object")
  205.                     searchResultsTextField;
  206.                 break;
  207.             case "*connect to field*":
  208.                 scrollField -edit 
  209.                     -text ("This menu item has been renamed.\n"
  210.                     + "Fields->Affect Selected Object")
  211.                     searchResultsTextField;
  212.                 break;
  213.             case "*connect to emitter*":
  214.                 scrollField -edit 
  215.                     -text ("This menu item has been renamed.\n"
  216.                     + "Particles->Use Selected Emitter")
  217.                     searchResultsTextField;
  218.                 break;
  219.             case "*connect to collision*":
  220.                 scrollField -edit 
  221.                     -text ("This menu item has been renamed.\n"
  222.                     + "Particles->Make Collide")
  223.                     searchResultsTextField;
  224.                 break;
  225.             case "*add to owner*":
  226.                 scrollField -edit 
  227.                     -text ("This menu item has been renamed.\n"
  228.                     + "Fields->Attach to Selected Object as Source")
  229.                     searchResultsTextField;
  230.                 break;
  231.             case "*scene caching*":
  232.                 scrollField -edit 
  233.                     -text ("This menu item has been renamed.\n"
  234.                     + "Solvers->Memory Caching")
  235.                     searchResultsTextField;
  236.                 break;
  237.  
  238.             case "*show only viewing panes*":
  239.                 scrollField -edit 
  240.                     -text ("This menu item has been renamed to Hide UI Elements.\n"
  241.                     + "Display->UI Elements->Hide UI Elements")
  242.                     searchResultsTextField;
  243.                 break;
  244.             case "*show all panes*":
  245.                 scrollField -edit 
  246.                     -text ("This menu item has been renamed to Restore UI Elements.\n"
  247.                     + "Display->UI Elements->Restore UI Elements")
  248.                     searchResultsTextField;
  249.                 break;
  250.  
  251.             case "*display poly count*":
  252.                 scrollField -edit 
  253.                     -text ("This menu item has been renamed to Poly Count.\n"
  254.                     + "Display->Heads Up Display->Poly Count")
  255.                     searchResultsTextField;
  256.                 break;
  257.             case "*set normal*":
  258.                 scrollField -edit 
  259.                     -text ("This menu item has been renamed to Set Vertex Normal.\n"
  260.                     + "Edit Polygons->Normals->Set Vertex Normal")
  261.                     searchResultsTextField;
  262.                 break;
  263.             case "*show edits at current level*":
  264.                 scrollField -edit 
  265.                     -text ("This menu item has been renamed to\n"
  266.                     + "Subdiv Surfaces->Component Display Filter->Edits")
  267.                     searchResultsTextField;
  268.                 break;
  269.             case "*refine display region*":
  270.                 scrollField -edit 
  271.                     -text ("This menu item has been renamed to\n"
  272.                     + "Subdiv Surfaces->Refine Selected Components")
  273.                     searchResultsTextField;
  274.                 break;
  275.             case "*expand display region*":
  276.                 scrollField -edit 
  277.                     -text ("This menu item has been renamed to\n"
  278.                     + "Subdiv Surfaces->Expand Selected Components")
  279.                     searchResultsTextField;
  280.                 break;
  281.  
  282.             case "*ui preferences*":
  283.             case "*general preferences*":
  284.                 scrollField -edit 
  285.                     -text ("This menu item has been renamed to Preferences.\n"
  286.                     + "Window->Settings/Preferences->Preferences")
  287.                     searchResultsTextField;
  288.                 break;
  289.         
  290.             default:
  291.                 $retVal = false;
  292.                 break;
  293.         }
  294.         if ($retVal) break;
  295.     }
  296.     
  297.     return $retVal;
  298. }
  299.  
  300.  
  301. global proc searchAllMenus (string $searchStringArg)
  302. {
  303.     if ($searchStringArg == "") {
  304.         scrollField -edit 
  305.             -text "Enter a string in the field above."
  306.             searchResultsTextField;
  307.         return;
  308.     }
  309.  
  310.     // Clear any old searches
  311.     scrollField -edit -clear searchResultsTextField;
  312.     
  313.     string $searchString;
  314.     if (!`checkBox -q -v searchCaseSensitive`) {
  315.         $searchString = tolower($searchStringArg);
  316.     } else {
  317.         $searchString = $searchStringArg;
  318.     }
  319.     $searchString = "*"+$searchString+"*";
  320.  
  321.     global string $gSearchLastString;
  322.     $gSearchLastString = $searchStringArg;
  323.     
  324.     global string $gMainWindow;
  325.     int $numMenus = `window -q -nm $gMainWindow`;
  326.  
  327.     // This should never tbe true
  328.     if ($numMenus < 1 ) exit;
  329.  
  330.     waitCursor -state on;
  331.     
  332.     string $aMenu;
  333.     string $menuLabel;
  334.     string $menuList[] = `window -q -ma $gMainWindow`;
  335.     string $path;
  336.     int $gotOne = 0;
  337.  
  338.     for ($aMenu in $menuList) {
  339.  
  340.         // Make sure nothing really strange is going on
  341.         if (!`menu -exists $aMenu`) continue;
  342.  
  343.         $menuLabel = `menu -q -l $aMenu`;
  344.             
  345.         // Skip the hotbox menus
  346.         string $s = match("Hotbox", $menuLabel);
  347.         if ($s == "Hotbox") continue;
  348.         if ($aMenu == "HotBoxRecentCommandsMenu") continue;
  349.  
  350.         $path = $menuLabel+"->";
  351.         if (searchOneMenu($aMenu,$searchString, $path)) {
  352.             $gotOne = 1;
  353.         }
  354.     }
  355.  
  356.     if ($gotOne) {
  357.         scrollField -edit 
  358.             -it "\nNo more matches found.\n"
  359.             searchResultsTextField;
  360.     } else {
  361.         // Look for menu items from previous versions
  362.         if (!$gotOne) {
  363.             $gotOne = `oldMenuSearch ($searchString)`;
  364.         }
  365.         
  366.         // If nothing was found then help a little
  367.         if (!$gotOne) {
  368.             scrollField -edit 
  369.                 -text ("No matches found.\n\n"
  370.                 + "Use wildcard characters (*) to expand your search.\n"
  371.                 + "Type a full name to find removed or renamed items.")
  372.                 searchResultsTextField;
  373.         }
  374.     }
  375.     
  376.     waitCursor -state off;
  377. }
  378.  
  379.  
  380. global proc findMenuItem ()
  381. {
  382.     global string $gSearchLastString = "";
  383.  
  384.     //    If the window already exists then just show it and return.
  385.     //
  386.     if (`window -exists menuSearchWindow`) {
  387.         showWindow menuSearchWindow;
  388.         return;
  389.     }
  390.  
  391.     window 
  392.         -title "Find a Menu Item" 
  393.         -iconName "Find Menu"
  394.         -w 435 -h 250
  395.         menuSearchWindow;
  396.         
  397.     formLayout searchForm;
  398.         text -l "Enter a string to search for:  " searchDirections;
  399.  
  400.         textField 
  401.             -cc "searchAllMenus (`textField -q -tx searchStringField`)"
  402.             searchStringField;
  403.  
  404.         checkBox -l "Use Case Sensitive Search" -v false searchCaseSensitive;
  405.  
  406.         scrollField -editable false -height 250 searchResultsTextField;
  407.  
  408.         button -l "Close" 
  409.             -c "window -e -visible false menuSearchWindow"
  410.             searchCloseButton;
  411.  
  412.     setParent ..;
  413.     
  414.     int $spacing = 5;
  415.     formLayout -e
  416.         -af searchDirections "left" $spacing
  417.         -af searchDirections "top" $spacing
  418.         
  419.         -af searchStringField "left" $spacing
  420.         -ac searchStringField "top" $spacing searchDirections
  421.         -af searchStringField "right" $spacing
  422.         
  423.         -af searchCaseSensitive "left" $spacing
  424.         -ac searchCaseSensitive "top" 1 searchStringField
  425.         -af searchCaseSensitive "right" $spacing
  426.         
  427.         -af searchResultsTextField "left" $spacing
  428.         -af searchResultsTextField "right" $spacing
  429.         -ac searchResultsTextField "top" 0 searchCaseSensitive
  430.         -ac searchResultsTextField "bottom" $spacing searchCloseButton
  431.         
  432.         -af searchCloseButton "left" $spacing
  433.         -af searchCloseButton "right" $spacing
  434.         -an searchCloseButton "top" 
  435.         -af searchCloseButton "bottom" $spacing
  436.         
  437.         searchForm;
  438.         
  439.     showWindow menuSearchWindow;
  440. }
  441.